package com.yhl.vocation.controller;

import com.yhl.vocation.service.VacationService;
import com.yhl.vocation.util.ResUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("vacation")
/**
 * @Description
 * @Author Date 2023/2/28-0:37
 */
public class VacationController {
    private VacationService vacationService;

    public VacationController(VacationService vacationService) {
        this.vacationService = vacationService;
    }

    @GetMapping("create")
    public String create(String openid, String start, String end, String type, String description) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date starts = simpleDateFormat.parse(start);
        Date ends = simpleDateFormat.parse(end);;
        if(vacationService.create(openid,starts,ends,type,description)){
            return ResUtil.build("200","请假信息提交成功");
        }
        return ResUtil.build("200", "请假信息提交失败");
    }

    @GetMapping("history")
    public String history(String openid){
        return ResUtil.build("200", vacationService.listByOpenId(openid));
    }

    @GetMapping("destory")
    public String destory(Integer id , String openid, String description){
        if(vacationService.destory(id,openid, description)){
            return ResUtil.build("600", "数据提交成功");
        }else {
            return ResUtil.build("600", "销假失败");
        }
    }
}
